Components Interaction
Components in Porto like in many other architectures can interact with each other. However, we should be mindful of the dependencies across containers and especially across sections, if you intend to split into micro-services with ease.
Components Interaction Diagram
Request Life Cycle
The Request Life Cycle is the process through which an API call navigates through the main components of a Porto application. The following steps describe a basic API call scenario:
- The User calls an
Endpointin aRoutefile. Endpointcalls aMiddlewareto handle the Authentication.Endpointcalls its correspondingControllerfunction.- The
Requestobject, which is automatically injected in theController, applies the request validation and authorization rules. Controllercalls anActionand passes the data from theRequestobject to it.Actionexecutes the business logic, by calling multipleTasks.Tasksexecute reusable subsets of the business logic, with eachTaskresponsible for a single portion of the mainAction.Actionprepares the final result to be returned to theController, and may collect data from theTasksif needed.Controllerbuilds the response using aVieworTransformer, and sends it back to the User.
Views: should be used in case the App serves HTML pages.
Transformers: should be used in case the App serves JSON or XML data.
It is important to note that the Request object handles request validation (and optionally, authorization rules, unless they are handled by middlewares.), while the Action executes the business logic by calling Tasks. The Tasks are used to execute reusable subsets of the business logic, with each Task responsible for a single portion of the main Action. The View or Transformer is used to build the response that is sent back to the User.
Everything triggered before the controller pertains to the interface with the external system, such as the web or potentially blockchain in the future. Meanwhile, everything after the controller relates to your business logic, which remains reusable regardless of the external system.